﻿using BLL;
using Model;

namespace StudentClubMisWf
{
    public partial class frmShowUserInfo : Form
    {
        public frmShowUserInfo()
        {
            InitializeComponent();
        }

        public ClubUser? clubUser;
        private void frmShowUserInfo_Load(object sender, EventArgs e)
        {
            if (clubUser is null)
            {
                MessageBox.Show("用户不存在！");
                return;
            }
            txtUserInfo.Text = clubUser?.UserName;
            txtRole.Text = clubUser?.Role;
            txtPassword.PasswordChar = '*';
            txtPassword.Text = clubUser?.Password;
        }

        private void txtModify_Click(object sender, EventArgs e)
        {
            txtUserInfo.ReadOnly = false; txtRole.ReadOnly = false; txtPassword.ReadOnly = false;
        }

        private void txtUpdate_Click(object sender, EventArgs e)
        {
            ClubUserBLL clubUserBLL = new ClubUserBLL();
            ClubUser u = new();
            u.Id = clubUser.Id;
            u.UserName = txtUserInfo.Text;
            u.Role = txtRole.Text;
            u.Password = txtPassword.Text;
            if (clubUserBLL.UpdateClubUser(u) > 0)
            {
                MessageBox.Show("更新成功！");

            }
            else
            {
                MessageBox.Show("更新失败，请检查数据库连接！");
            }

        }
    }
}
